#include "includes.h"
uint8_T returnValue[20];


void BMS_Start_Task(void)
{

	xTaskCreate(App_VCUCAN_RxTask,               "App_VCAN_RxTask",             (uint16_t)400, NULL, VCUCOMM_RX_TASK_PRIO, NULL);//USED 212

	xTaskCreate(App_VCUCAN_TxTask,    			 "App_VCAN_TxTask",  			(uint16_t)500, NULL, VCUCOMM_TX_TASK_PRIO, NULL);//USED 192

	#if Bccfg_BCU_QchrgFuncUse
	xTaskCreate(rte_qchgFlowTask,                "rte_qchgFlowTask",            (uint16_t)400, NULL, DCCHARGER_TX_TASK_PRIO, NULL);//USED 202
	#endif

	#if  Bccfg_BCU_SlaveFuncUse
	xTaskCreate(App_ICAN_RxTask,                 "App_ICAN_RxTask",             (uint16_t)300, NULL, INCOMM_RX_TASK_PRIO, NULL);//USED  111
	#endif

	xTaskCreate(App_DataWriteTask,               "App_DataWriteTask",     		(uint16_t)400, NULL, SYSPARAM_SAVE_TASK_PRIO, NULL);//USED 212

	xTaskCreate(App_SignalSmpTask,      	     "App_SignalSmpTask",  		    (uint16_t)400, NULL, BATTERY_SCAN_TASK_PRIO, NULL);//USED 191

	#if Bccfg_BCU_QchrgFuncUse
	xTaskCreate(App_CCAN_RxTask,                 "App_CCAN_RxTask",             (uint16_t)300, NULL, CHARGER_RX_TASK_PRIO, NULL);//USED 111
	#endif
	xTaskCreate(App_UdsTask,     				 "App_UdsTask", 				(uint16_t)400, NULL, UDS_TASK_PRIO, NULL);//USED 202

	xTaskCreate(rte_pwrTask,                     "rte_pwrTask",                 (uint16_t)400, NULL, RTE_PWR_TASK_PRIO, NULL);//USED  212

	xTaskCreate(rte_soxTask,                     "rte_soxTask",                 (uint16_t)400, NULL, RTE_SOX_TASK_PRIO, NULL);//USED 202

	xTaskCreate(rte_faultTask,                   "rte_faultTask",               (uint16_t)300, NULL, RTE_FAULT_TASK_PRIO, NULL);//USED 153

	#if Bccfg_BCU_SlaveFuncUse
	xTaskCreate(App_ICAN_TxTask,    			 "App_ICAN_TxTask",  			(uint16_t)400, NULL, INCOMM_TX_TASK_PRIO, NULL);//USED 212
	#endif

	xTaskCreate(App_CellInfoSmpTask,      	     "App_CellInfoSmpTask",  	    (uint16_t)600, NULL, AFE_TASK_PRIO, NULL);//USED  145

	#if Bccfg_BCU_ExDflashUseType
	xTaskCreate(App_DataRecordTask,              "App_DataRecordTask",			(uint16_t)400, NULL, DAT_RECORD_TASK_PRIO, NULL);//USED  204
	#endif

	vTaskStartScheduler();
}

TickType_t OsTaskGetTickCount(void)
{
	return xTaskGetTickCount();
}

void OsTaskCreate(TaskFunction_t pxTaskCode, const char * const pcName,const uint16_t usStackDepth,unsigned long uxPriority)
{
	xTaskCreate(pxTaskCode, pcName ,  (uint16_t)usStackDepth, NULL, uxPriority, NULL);
}

void OsTaskDelayUntil(TickType_t *pxPreviousWakeTime,TickType_t xTimeIncrement )
{
	vTaskDelayUntil( pxPreviousWakeTime, xTimeIncrement );
}

void vApplicationStackOverflowHook(TaskHandle_t pxTask, char *pcTaskName)
{
	( void ) pcTaskName;
	( void ) pxTask;
/* 	Run time stack overflow checking is performed if
	configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook
	function is called if a stack overflow is detected. */
	taskDISABLE_INTERRUPTS();
	for( ;; );
}
/*-----------------------------------------------------------*/

void vApplicationIdleHook(void)
{
    volatile size_t xFreeHeapSpace;
/* 	This function is called on each cycle of the idle task.  In this case it
	does nothing useful, other than report the amount of FreeRTOS heap that
	remains unallocated. */
	xFreeHeapSpace = xPortGetFreeHeapSize();
	if( xFreeHeapSpace > 100)
	{
		/* By now, the kernel has allocated everything it is going to, so
		if there is a lot of heap remaining unallocated then
		the value of configTOTAL_HEAP_SIZE in FreeRTOSConfig.h can be
		reduced accordingly. */
	}
}

void vApplicationTickHook(void)
{

}

void vApplicationMallocFailedHook( void )
{
	/* Called if a call to pvPortMalloc() fails because there is insufficient
	free memory available in the FreeRTOS heap.  pvPortMalloc() is called
	internally by FreeRTOS API functions that create tasks, queues, software
	timers, and semaphores.  The size of the FreeRTOS heap is set by the
	configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
	taskDISABLE_INTERRUPTS();
	for( ;; );
}
